--
-- Author: ping.wang
-- Date: 2019-02-26 17:13:54
--
-- RewardMonitorGivePanel
--
local RewardWelfareGiveRender = import(".renders.RewardWelfareGiveRender")
local NewListAdapterTool = require("app.widget.NewListAdapterTool")
local ClassRef = app.mvc.createPanelClass(...)

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.RewardWelfareGivePanel))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)
    self:setContentSize( self._ui.Panel:getContentSize() )
    self._icon = self._ui.icon --福利icon
    self._tltBg = self._ui.bg02 --标题背景
    self._tlt = self._ui.tlt --标题名
    self._des = self._ui.Text_1 --描述
    self._traceBtn = self._ui.selected_btn --追踪按钮
    self._rankBtn = self._ui.rank_btn

    self._traceBtn:setVisible(false)
    self._rankBtn:setVisible(false)


    local params = {
        list = self._ui.ScrollView,
        subPanelClass = RewardWelfareGiveRender
    }
    self._taskListnode = NewListAdapterTool.new( params )
    self._taskListnode:setSubPanelCB( handler( self, self._taskRenderOpCb ) )

    self:refresh()
end

function ClassRef:refresh()
    if self._data then
        self:setVisible( true )

        local data = self._data
        if data.icon then
            self._icon:loadTexture(Res.activityIconPath..data.icon..".png")
        else
            self._icon:loadTexture(Res.activityIconPath.."activity_0.png")
        end

        self._tlt:setString(L(data.name))
        if data.finishTime == 0 then
            self._des:setString(L(data.desc))
        else
            local date1 = os.date("%Y.%m.%d", math.floor(data.startTime))
            local date2 = os.date("%Y.%m.%d", math.floor(data.finishTime))

            self._des:setString(string.format(L("activitydes_9999"),L(data.desc),string.format("%s ~ %s",date1,date2) ) )
        end
        self._taskListnode:refreshList(data.tasks)
    else
        self:setVisible( false )
    end
end

function ClassRef:onOperate(cb)
    self._onOperate = cb
end

function ClassRef:_taskRenderOpCb( op, data )
    executeFunc(self._onOperate, op, data)
end

function ClassRef:setData(data)
    self._data = data
    self:refresh()
end

return ClassRef

